package com.egg.ylt.presenter.impl;

import com.egg.ylt.Utils.API;
import com.egg.ylt.pojo.PayTypeEntity;
import com.egg.ylt.presenter.ICardPayPresenter;
import com.egg.ylt.view.ICardPayView;
import com.yonyou.framework.library.bean.ErrorBean;
import com.yonyou.framework.library.common.CommonUtils;
import com.yonyou.framework.library.mvp.impl.BasePresenter;
import com.yonyou.framework.library.net.ReqCallBack;
import com.yonyou.framework.library.net.RequestManager;

import java.util.HashMap;

/**
 * Created by sichaoqi on 2018/10/17.
 */

public class CardPayPresenterImpl extends BasePresenter<ICardPayView> implements ICardPayPresenter {
    @Override
    public void getAlipayOrderInfo(String token, String companyId, String payType, String cardId, String cardName,
                                   String cardPrice, String id,String ticketId, String ticketAmount) {
        mView.showDialogLoading("数据加载中");
        HashMap<String, String> hashMap = new HashMap<>();
        hashMap.put("token", token);
        hashMap.put("companyId", companyId);
        hashMap.put("payType", payType);
        hashMap.put("cardId", cardId);
        hashMap.put("cardName", cardName);
        hashMap.put("cardPrice", cardPrice);
        hashMap.put("id", id);
        hashMap.put("ticketId", ticketId);
        hashMap.put("ticketAmount", ticketAmount);
        RequestManager.getInstance().requestPostByAsyn(API.GET_BUY_TIMES_CARD, hashMap, new ReqCallBack<String>() {

            @Override
            public void onReqSuccess(String result) {
                mView.dismissDialogLoading();
                mView.resolveAlipayOrder(result);
            }

            @Override
            public void onFailure(String result) {
                mView.dismissDialogLoading();
                CommonUtils.makeEventToast(mContext, result, false);
            }

            @Override
            public void onReqFailed(ErrorBean error) {
                mView.dismissDialogLoading();
                CommonUtils.makeEventToast(mContext, error.getMsg(), false);
            }
        });
    }

    @Override
    public void getWXOrderInfo(String token, String companyId, String payType, String cardId, String cardName,
                               String cardPrice, String id, String ticketId, String ticketAmount) {
        mView.showDialogLoading("数据加载中");
        HashMap<String, String> hashMap = new HashMap<>();
        hashMap.put("token", token);
        hashMap.put("companyId", companyId);
        hashMap.put("payType", payType);
        hashMap.put("cardId", cardId);
        hashMap.put("cardName", cardName);
        hashMap.put("cardPrice", cardPrice);
        hashMap.put("id", id);
        hashMap.put("ticketId", ticketId);
        hashMap.put("ticketAmount", ticketAmount);
        RequestManager.getInstance().requestPostByAsyn(API.GET_BUY_TIMES__WECHAT, hashMap, new ReqCallBack<String>() {

            @Override
            public void onReqSuccess(String result) {
                mView.dismissDialogLoading();
                mView.resolveWxOrder(result);
            }

            @Override
            public void onFailure(String result) {
                mView.dismissDialogLoading();
                CommonUtils.makeEventToast(mContext, result, false);
            }

            @Override
            public void onReqFailed(ErrorBean error) {
                mView.dismissDialogLoading();
                CommonUtils.makeEventToast(mContext, error.getMsg(), false);
            }
        });
    }

    @Override
    public void getPayType(String token, String id, String companyId) {
        mView.showDialogLoading("数据加载中");
        HashMap<String, String> hashMap = new HashMap<>();
        hashMap.put("token", token);
        hashMap.put("id", id);
        hashMap.put("companyId", companyId);

        RequestManager.getInstance().requestGetByAsyn(API.POST_PAY_TYPE, hashMap, new ReqCallBack<PayTypeEntity>() {

            @Override
            public void onReqSuccess(PayTypeEntity result) {
                mView.dismissDialogLoading();
                mView.getPayData(result);
            }

            @Override
            public void onFailure(String result) {
                mView.dismissDialogLoading();
                CommonUtils.makeEventToast(mContext, result, false);
            }

            @Override
            public void onReqFailed(ErrorBean error) {
                mView.dismissDialogLoading();
                CommonUtils.makeEventToast(mContext, error.getMsg(), false);
            }
        });
    }
}
